home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvhc11a.zip / TVHC2MSG.PAS < prev   
Pascal/Delphi Source File  |  1993-12-27  |  5KB  |  183 lines

  1. (***************************************************************************
  2.   TVHC2MSG program
  3.   TVHC filter for using TVHC as an IDE tool
  4.   PJB December 23, 1993, Internet mail to d91-pbr@nada.kth.se
  5.   Copyright 1993, All Rights Reserved
  6.   Free source, use at your own risk.
  7.   If modified, please state so if you pass this around.
  8.  
  9.   This is TVHC filter for the IDE, but you can use TASM2MSG if you change
  10.   TVHC a little. Unfortunately there is a filter bug in the BP 7.0 IDE
  11.   which this filter bypasses, so you're better off with this filter if
  12.   your IDE has the bug.
  13.  
  14.   Suggestion:
  15.   Use the modified TVHC included in this package to get pin-pointing
  16.   line references along with your help messages from TVHC.
  17.  
  18.  
  19.   GRIPE:
  20.     If you do NOT use a patched TVHC, this file will direct the IDE to
  21.     the *.HLP file, not the .TXT one. This is a stupid TVHC bug, you can
  22.     either change TVHC's PrntMsg or define ForceExtension (see below)
  23.     before you compile this file.
  24.  
  25.   Defining ForceExtension tells the IDE that the help input file
  26.   (usually .TXT) is the base name of the output help file (usually .HLP)
  27.   but with the extension .TXT. THIS WILL NOT WORK IF YOUR OUTPUT FILE'S
  28.   BASE NAME IS DIFFERENT THAN THAT OF YOUR INPUT FILE. In other words,
  29.   this will fail (because the IDE will look for MYPROG.TXT):
  30.  
  31.     TVHC HELP.TXT MYPROG.HLP   { Won't work with Borland's TVHC and TVHC2MSG }
  32.  
  33.  
  34.   Instructions:
  35.   Compile this program, put the resulting EXE somewhere in your path,
  36.   add a TVHC tool under Options│Tools if you haven't already done so and
  37.   add this to the Tool's command line along with a help file name:
  38.  
  39.     $SAVE ALL $CAP MSG(TVHC2MSG) $NOSWAP
  40.  
  41. ***************************************************************************)
  42.  
  43. (* Remove the first two spaces if you don't want to use a modified TVHC *)
  44. {  $DEFINE ForceExtension}
  45.  
  46.  
  47.  
  48. {************************************************}
  49. {                                                }
  50. {   Grep message filter example                  }
  51. {   Copyright (c) 1992 by Borland International  }
  52. {                                                }
  53. {************************************************}
  54.  
  55. program Grep2Msg;
  56.  
  57. {$M 4096,0,0}
  58.  
  59. { Message filters read input from the target program (in this case, GREP)
  60.   by way of StdIn (by using Read or ReadLn), filter the input, then write
  61.   output back to StdOut (using Write or WriteLn). The IDE takes care of
  62.   redirecting the transfer program's output to the filter program, as well
  63.   as redirecting the filter program's output back to the IDE itself.
  64. }
  65.  
  66. {$I-,S-}
  67.  
  68. uses
  69.   Dos;
  70.  
  71. var
  72.   LineNo, E: Word;
  73.   Line: String;
  74.   InputBuffer: array[0..4095] of Char;
  75.   OutputBuffer: array[0..4095] of Char;
  76.  
  77.  
  78. (*******************************************************************
  79.   Force extension
  80. *******************************************************************)
  81. function ForceExtension(const FileName, Ext:String):String;
  82.   var
  83.     P: PathStr;
  84.     D: DirStr;
  85.     N: NameStr;
  86.     E: ExtStr;
  87. begin
  88.   FSplit(FileName, D, N, E);
  89.   E:=Ext;
  90.   ForceExtension:=D+N+E;
  91. end;
  92.  
  93.  
  94. { The first data passed back to the IDE by a message filter must always
  95.   be the string 'BI#PIP#OK', followed by a null terminator.
  96. }
  97. procedure WriteHeader;
  98. begin
  99.   Write('BI#PIP#OK'#0);
  100. end;
  101.  
  102. { The beginning of a new file is marked by a #0, the file's name, terminated
  103.   by a #0 character.
  104. }
  105. procedure WriteNewFile(const FileName: String);
  106. begin
  107.   Write(#0, FileName, #0);
  108. end;
  109.  
  110. { Each message line begins with a #1, followed the line number (in low/high 
  111.   order), followed by the column number (in low/high order), then the
  112.   message text itself, terminated with a #0 character.
  113. }
  114. procedure WriteMessage(Line, Col: Word; const Message: String);
  115. begin
  116.   Write(#1, Chr(Lo(Line)), Chr(Hi(Line)), Chr(Lo(Col)), Chr(Hi(Col)),
  117.     Message, #0);
  118. end;
  119.  
  120. { The end of the input stream is marked by a #127 character }
  121. procedure WriteEnd;
  122. begin
  123.   Write(#127);
  124. end;
  125.  
  126. function TrimLeft(S:String): String;
  127. var
  128.   i: Integer;
  129.   n: String;
  130. begin
  131.   i := 1;
  132.   while (i <= Length(s)) and (s[i] = #32) do Inc(i);
  133.   if i <= Length(s) then
  134.   begin
  135.     Move(s[i], n[1], Length(s) - i + 1);
  136.     n[0] := Char(Length(s) - i + 1);
  137.   end
  138.   else n[0] := #0;
  139.   TrimLeft := n;
  140. end;
  141.  
  142.   var
  143.     LPara, RPara, FirstColon : Integer;
  144.  
  145. begin
  146.   SetTextBuf(Input, InputBuffer);
  147.   SetTextBuf(Output, OutputBuffer);
  148.  
  149.   (* Skip banner msg *)
  150.   if not Eof then
  151.     ReadLn(Line);
  152.  
  153.   WriteHeader;
  154.   while not Eof do
  155.   begin
  156.     ReadLn(Line);
  157.     if Line <> '' then
  158.     begin
  159.       LPara:=Pos('(', Line);
  160.       RPara:=Pos(')', Line);
  161.       FirstColon:=Pos(':', Line);
  162.  
  163.       Val(Copy(Line, LPara+1, RPara-(LPara+1)), LineNo, E);
  164.       if E = 0 then
  165.       begin
  166.         WriteNewFile(TrimLeft(Copy(Line, FirstColon+1, LPara-(FirstColon+1))));
  167.        {$IFDEF ForceExtension}
  168.         WriteNewFile(ForceExtension(
  169.         TrimLeft(Copy(Line, FirstColon+1, LPara-(FirstColon+1))),
  170.         '.TXT'));
  171.        {$ELSE}
  172.         WriteNewFile(TrimLeft(Copy(Line, FirstColon+1, LPara-(FirstColon+1))));
  173.        {$ENDIF}
  174.         WriteMessage(LineNo, 1, TrimLeft(Copy(Line, RPara+2, 255)));
  175.       end
  176.       else
  177.         WriteMessage(0, 1, Line);
  178.     end;
  179.   end;
  180.   WriteNewFile('');     (* This fixes a bug in the BP 7.0 IDE *)
  181.   WriteEnd;
  182. end.
  183.